﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Talk.AutoMap.Extensions
{
    public static class AutoMapExtension
    {
         
        public static TDestination MapTo<TDestination>(this object source)
        {
            return Mapper.Map<TDestination>(source);
        }
        
        public static TDestination MapTo<TSource, TDestination>(this TSource source, TDestination destination)
        {
            return Mapper.Map(source, destination);
        }

        public static List<TDestination> MapToList<TDestination>(this IEnumerable<object> source)
        {
            if (source == null || !source.Any())
                return new List<TDestination>();
            return source.Select(t => t.MapTo<TDestination>()).ToList();
        }
    }
}
